﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import org.aswing.*;
    import Display.MarketUI.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class DataItemCell extends JPanel implements GridListCell {

        protected var m_item;
        protected var m_loader:Loader;
        protected var m_itemIcon:DisplayObject;
        protected var m_gridList:GridList;
        protected var m_index:int;

        public function DataItemCell(_arg1:LayoutManager=null){
            super(_arg1);
            ASwingHelper.prepare(this);
        }
        public function setGridListCellStatus(_arg1:GridList, _arg2:Boolean, _arg3:int):void{
            if (_arg1){
                this.m_gridList = _arg1;
                this.m_index = _arg3;
                _arg1.setTileWidth(this.getPreferredWidth());
                _arg1.setTileHeight(this.getPreferredHeight());
            };
        }
        public function setCellValue(_arg1):void{
            this.m_item = _arg1;
            var _local2:String = Global.gameSettings.getImageByName(this.m_item.name, "icon");
            this.m_loader = LoadingManager.load(_local2, this.onIconLoad, LoadingManager.PRIORITY_HIGH);
        }
        public function getCellValue(){
            return (this.m_item);
        }
        public function getCellComponent():Component{
            return (this);
        }
        protected function scaleToFit(_arg1:DisplayObject):Number{
            var _local2:Number = 1;
            var _local3:Number = 1;
            var _local4:int = (Catalog.CARD_HEIGHT - Catalog.CARD_OFFSET);
            var _local5:int = (Catalog.CARD_WIDTH - Catalog.CARD_OFFSET);
            if (_arg1.width > _local5){
                _local2 = (_local5 / _arg1.width);
            };
            if (_arg1.height > _local4){
                _local3 = (_local4 / _arg1.height);
            };
            return (Math.min(_local2, _local3));
        }
        protected function onIconLoad(_arg1:Event):void{
            if (this.m_loader){
                this.m_itemIcon = this.m_loader;
            };
            this.m_itemIcon.scaleX = (this.m_itemIcon.scaleY = this.scaleToFit(this.m_itemIcon));
            this.initializeCell();
            this.setGridListCellStatus(this.m_gridList, false, this.m_index);
        }
        protected function initializeCell():void{
        }

    }
}//package Display 
